package com.example.demo.easyexcel.db.repository;

import com.example.demo.easyexcel.db.entity.City;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


/**
 * @author zjq
 * @version 创建时间：2021-12-23 10:36:56
 */

@Repository
public interface CityRepository extends JpaRepository<City, Integer> {

    @Query(value = "SELECT * FROM city ", nativeQuery = true)
    List<City> getCity();

    @Query(value = "SELECT id FROM city where name =?1 ", nativeQuery = true)
    List<Integer> getCityId(String name);

    @Modifying
    @Transactional
    @Query(value = "update City set photo=:photo where id = (:id) ")
    int updatePhoto(@Param("photo") String photo, @Param("id") Integer id);
}
